/*
 * Copyright 2022 The Open Islands Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openislands.oi.dao.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.ColumnType;
import com.gitee.sunchenbin.mybatis.actable.annotation.Index;
import com.gitee.sunchenbin.mybatis.actable.annotation.Unique;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import org.apache.ibatis.type.EnumTypeHandler;
import org.openislands.oi.config.typehandler.JsonTypeHandler;
import org.openislands.oi.constant.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

@TableName(value = "t_task", autoResultMap = true)
public class TaskDO extends BaseDO implements Serializable {
    @Unique(columns = {"f_job_id", "f_task_name", "f_task_version"})
    @Index
    @Column(isNull = false, length = 64)
    @TableField("f_job_id")
    private String jobId;
    @TableField("f_leader_node")
    @Column(isNull = false, length = 64)
    private String leaderNode;
    @TableField(value = "f_nodes", typeHandler = JsonTypeHandler.FederatedNodes.class)
    @Column(type = MySqlTypeConstant.TEXT, isNull = false)
    private Map<RoleType, List<String>> nodes;
    @Index
    @Column(isNull = false, length = 64)
    @TableField("f_task_name")
    private String taskName;
    @TableField("f_task_version")
    @Column(isNull = false)
    private Integer taskVersion;
    @Column(type = MySqlTypeConstant.VARCHAR, isNull = false, length = 48)
    @TableField(value = "f_execution_environment", typeHandler = EnumTypeHandler.class)
    private ExecutionEnvironment executionEnvironment;
    @Column(type = MySqlTypeConstant.VARCHAR, isNull = false, length = 48)
    @TableField(value = "f_operator_type", typeHandler = EnumTypeHandler.class)
    private OperatorType operatorType;
    @Column(type = MySqlTypeConstant.VARCHAR, isNull = false, length = 48)
    @TableField(value = "f_operator_algorithm", typeHandler = EnumTypeHandler.class)
    private AlgorithmType operatorAlgorithm;
    @TableField("f_operator_vendor")
    private String operatorVendor;
    @TableField("f_operator_version")
    private String operatorVersion;

    @TableField(value = "f_output_data_format", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 31, isNull = false)
    private DataFormat outputDataFormat;

    @TableField(value = "f_output_model_format", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 31, isNull = false)
    private ModelFormat outputModelFormat;

    @TableField("f_task_config")
    @Column(type = MySqlTypeConstant.TEXT, isNull = false)
    private String taskConfig;

    @TableField(value = "f_next_state", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 31, isNull = false)
    private TaskState nextState;
    @TableField(value = "f_state", typeHandler = EnumTypeHandler.class)
    @Column(type = MySqlTypeConstant.VARCHAR, length = 31, isNull = false)
    private TaskState state;
    @TableField("f_progress")
    @Column(isNull = false, defaultValue = "0")
    private Integer progress;
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_submitted_time")
    private Date submittedTime;
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_pending_time")
    private Date pendingTime;
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_activating_time")
    private Date activatingTime;
    @ColumnType(MySqlTypeConstant.TIMESTAMP)
    @TableField("f_end_time")
    private Date endTime;
    @TableField("f_auto_retries")
    @Column(isNull = false)
    private Integer autoRetries;
    @TableField("f_elapsed")
    @Column(isNull = false, defaultValue = "0")
    private Integer elapsed;

    public String getJobId() {
        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public Integer getTaskVersion() {
        return taskVersion;
    }

    public void setTaskVersion(Integer taskVersion) {
        this.taskVersion = taskVersion;
    }

    public OperatorType getOperatorType() {
        return operatorType;
    }

    public void setOperatorType(OperatorType operatorType) {
        this.operatorType = operatorType;
    }

    public AlgorithmType getOperatorAlgorithm() {
        return operatorAlgorithm;
    }

    public void setOperatorAlgorithm(AlgorithmType operatorAlgorithm) {
        this.operatorAlgorithm = operatorAlgorithm;
    }

    public String getTaskConfig() {
        return taskConfig;
    }

    public void setTaskConfig(String taskConfig) {
        this.taskConfig = taskConfig;
    }

    public Integer getProgress() {
        return progress;
    }

    public void setProgress(Integer progress) {
        this.progress = progress;
    }

    public Date getSubmittedTime() {
        return submittedTime;
    }

    public void setSubmittedTime(Date submittedTime) {
        this.submittedTime = submittedTime;
    }

    public Date getPendingTime() {
        return pendingTime;
    }

    public void setPendingTime(Date pendingTime) {
        this.pendingTime = pendingTime;
    }

    public Date getActivatingTime() {
        return activatingTime;
    }

    public void setActivatingTime(Date activatingTime) {
        this.activatingTime = activatingTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Integer getAutoRetries() {
        return autoRetries;
    }

    public void setAutoRetries(Integer autoRetries) {
        this.autoRetries = autoRetries;
    }

    public Integer getElapsed() {
        return elapsed;
    }

    public void setElapsed(Integer elapsed) {
        this.elapsed = elapsed;
    }

    public String getLeaderNode() {
        return leaderNode;
    }

    public void setLeaderNode(String leaderNode) {
        this.leaderNode = leaderNode;
    }

    public Map<RoleType, List<String>> getNodes() {
        return nodes;
    }

    public void setNodes(Map<RoleType, List<String>> nodes) {
        this.nodes = nodes;
    }

    public TaskState getState() {
        return state;
    }

    public void setState(TaskState state) {
        this.state = state;
    }

    public String getOperatorVendor() {
        return operatorVendor;
    }

    public void setOperatorVendor(String operatorVendor) {
        this.operatorVendor = operatorVendor;
    }

    public String getOperatorVersion() {
        return operatorVersion;
    }

    public void setOperatorVersion(String operatorVersion) {
        this.operatorVersion = operatorVersion;
    }

    public TaskState getNextState() {
        return nextState;
    }

    public void setNextState(TaskState nextState) {
        this.nextState = nextState;
    }

    public DataFormat getOutputDataFormat() {
        return outputDataFormat;
    }

    public void setOutputDataFormat(DataFormat outputDataFormat) {
        this.outputDataFormat = outputDataFormat;
    }

    public ModelFormat getOutputModelFormat() {
        return outputModelFormat;
    }

    public void setOutputModelFormat(ModelFormat outputModelFormat) {
        this.outputModelFormat = outputModelFormat;
    }

    public ExecutionEnvironment getExecutionEnvironment() {
        return executionEnvironment;
    }

    public void setExecutionEnvironment(ExecutionEnvironment executionEnvironment) {
        this.executionEnvironment = executionEnvironment;
    }
}